home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-04-03 | 2.3 KB | 80 lines | [TEXT/PJMM] |
- {======================}
- unit FKEY;
- {======================}
- interface
- {======================}
- procedure Main;
- {======================}
- implementation
- {======================}
- procedure Main;
- var
- dlgOrigin: Point; {Top-left corner of dialog box}
- theReply: SFReply; {Data returned by SFGet dialog}
- theFile: INTEGER; {Reference number of file}
- resultCode: OSErr; {I/O error code}
- TypeList: SFTypeList; {Type List to search for (unused) }
- Block: ParamBlockRec; {Used to get file reference number}
- WIND: WindowPtr; {Display Window }
- bounds: Rect; {window rectangle Rectangle }
- OldPort: GrafPtr; {Graf Port set upon entry}
- dummy: LONGINT; {parameter of Delay}
- {======================}
- { CenterDraw }
- { Input: String to Draw , line number to draw on. }
- { (String is centered horizontally on the window.) }
- {======================}
- procedure CenterDraw (s: Str255; y: INTEGER);
- var
- x: INTEGER;
- begin
- with WIND^.portRect do
- begin
- x := (right + left) div 2 - StringWidth(s) div 2;
- MoveTo(x, y * 16);
- end;
- DrawString(s);
- end;
- {======================}
- begin
- GetPort(OldPort);
- SetRect(bounds, 85, 40, 420, 100);
- WIND := NewWindow(nil, bounds, '', TRUE, dBoxProc, pointer(-1), FALSE, 0);
- SetPort(WIND);
- TextFace([underline]);
- CenterDraw('Close File FKEY', 1);
- TextFace([]);
- CenterDraw('Select the file you wish to close.', 2);
-
- SetPt(dlgOrigin, 85, 120); {Set up dialog origin}
- SFGetFile(dlgOrigin, '', nil, -1, TypeList, nil, TheReply);
-
- with TheReply do
- if good then
- begin
- {Try to open file}
- resultCode := FSOpen(fname, vRefNum, theFile);
- {if it was already open, get the file ref number}
- if resultCode = opWrErr then
- with Block do
- begin
- ioNamePtr := @fName;
- ioVRefNum := vRefNum;
- ioFDirIndex := -1;
- resultCode := PBGetFInfo(@Block, false); {Get Finder info}
- theFile := ioFRefNum;
- CenterDraw(Concat('“', fName, '” is now closed.'), 3);
- end
- else
- CenterDraw(Concat('“', fName, '” was not open.'), 3);
- {Do the actual closing... regardless if it was open before the FKEY or not}
- ResultCode := fsClose(theFile);
- end;
- Delay(45, dummy);{Wait a while 3/4 of second}
-
- DisposeWindow(WIND); {Close up}
- SetPort(OldPort);
- end;
- {======================}
- end.
- {======================}